package com.CI.CreateAccount.Business
{
	import com.CI.CreateAccount.VO.AdminVO;
	import com.CI.CreateAccount.VO.UserVO;
	
	import com.adobe.cairngorm.business.Responder;
	import com.adobe.cairngorm.business.ServiceLocator;
	
	import mx.rpc.AsyncToken;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.HTTPService;
	
	import mx.controls.Alert;
	
	public class AddDelegate
	{
		protected var responder : Responder;
		
		public function AddDelegate(responder : Responder)
		{
			this.responder = responder;
		}
		
		
		public function sendObject(obj : Object) : void
		{   
			var params : Object = new Object();
			var service : HTTPService;
			var token : AsyncToken;
			var responder:mx.rpc.Responder;
		
		    if(obj is UserVO)
		    {   
		    	var user : UserVO = new UserVO();
		    	user = obj as UserVO;
		    	params.action = 'AddNewUser';
		    	params.salutation = user.salutation;
		    	params.firstName = user.firstName;
		    	params.lastName = user.lastName;
		    	params.dateOfBirth = "";
		    	params.dateOfBirth = user.dateOfBirth;
		    	params.email = user.email;
		    	params.password = user.password;
		    	params.organization = "";
		    	params.organization = user.organization;
		    	params.title = "";
		    	params.title = user.title;
		    	params.departement = "";
		    	params.departement = user.departement;
		   
		        service = ServiceLocator.getInstance().getHTTPService("addNewUser");
		    	
		    	token = service.send(params);
				responder = new mx.rpc.Responder(Add_onResult, Add_onFault);
				token.addResponder(responder);
		    }
		    else
		    {  
		    	var admin : AdminVO = new AdminVO();
		    	admin = obj as AdminVO;
		    	params.action = 'AddNewAdmin';
		    	params.salutation = admin.salutation;
		    	params.firstName = admin.firstName;
		    	params.lastName = admin.lastName;
		    	params.dateOfBirth = "";
		    	params.dateOfBirth = admin.dateOfBirth;
		    	params.email = admin.email;
		    	params.password = admin.password;
		    	params.task = "";
		    	params.task = admin.task;
		    	params.permission = admin.permission;	    	
		    	
		    	service = ServiceLocator.getInstance().getHTTPService("addNewAdmin");
		    	
		        token = service.send(params);
				responder = new mx.rpc.Responder(Add_onResult, Add_onFault);
				token.addResponder(responder);
		    }
		}
		
		protected function Add_onResult(event:ResultEvent) : void
		{
			
		}
		
		protected function Add_onFault(event:FaultEvent) : void
		{
		
		}
	}
}